package com.sky.mapper;

import com.sky.annotations.AutoFill;
import com.sky.entity.CategoryEntity;
import com.sky.enumeration.CategoryTypeEnum;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    List<CategoryEntity> getByNameAndType(@Param("name") String name, @Param("type") CategoryTypeEnum type);

    @Delete("delete from category where id = #{id}")
    void del(Long id);

    @Select("select * from category where type = #{typeEnum}")
    List<CategoryEntity> getByType(CategoryTypeEnum typeEnum);

    @Insert("insert into category (id,type,name,sort,status,create_time,update_time,create_user,update_user) values (" +
            "null,#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void save(CategoryEntity entity);

    @AutoFill(OperationType.UPDATE)
    void update(CategoryEntity entity);

    @Select("select * from category")
    List<CategoryEntity> selectAll();
}
